package arrayDemo;

import java.util.Scanner;

/**
 * @author: snail_mount
 * @date: 20/1/28 23:21
 * @description: 案例需求:
 * (1)键盘录入5个int类型的数据存储数组arr中;
 * (2)定义方法将arr数组中的内容反转;
 * (3)定义方法对反转后的数组进行遍历;
 * int[] arr = {12,24,67,23,56,15};
 */
public class Reversal {
    public static void main(String[] args) {
        int[] arr = new int[5];
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入5个整数");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
//            System.out.print(arr[i] + ",");
        }
        previous(arr);
        reversalArray(arr);
        previous(arr);
    }

    private static void previous(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    private static void reversalArray(int[] arr) {
        for (int startIndex = 0, endIndex = arr.length - 1; startIndex <= endIndex; startIndex++, endIndex--) {
            int temp = arr[startIndex];
            arr[startIndex] = arr[endIndex];
            arr[endIndex] = temp;
        }
    }
}
